/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.solestac.dao;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.colswe.solestac.entity.RequestType;

/**
 *
 * @author David Cendales
 */
public class RequestTypeDao {
    
    /**Search all request types in the system.
     * @param em EntityManager object to make the operation
     * @return All registered request types
     */
    public List<RequestType> searchAll(final EntityManager em) {
        Query q = em.createNamedQuery("RequestType.findAll");
        return (List<RequestType>) q.getResultList();
    }
    
    /**Search a request type by the name.
     * @param em EntityManager object to make the operation
     * @param name Type request given by the user
     * @return request type by name
     */
    public List<RequestType> searchByName(final String name, final EntityManager em) {
        Query q = em.createNamedQuery("RequestType.findByName");
        q.setParameter("name", name);
        return (List<RequestType>) q.getResultList();
    }
    
     /**Update a request type.
     * @param t The request type object that will be updated
     * @param em EntityManager object to make the operation
     */
    public void update(final RequestType t, final EntityManager em) {
        em.merge(t);
    }
}
